require('babel-polyfill')
import Vue from 'vue'
import Router from 'vue-router'
import App from './App.vue'
import watch from './components/page/watch.vue'
import index from './components/page/index.vue'
import FastClick from 'fastclick'
import VueCarbon from './components/vue-carbon'
import RoomManage from './api/roomManage'
Vue.use(VueCarbon)
Vue.use(RoomManage)
Vue.filter('Round', (value) => {
  return value.toFixed(1)
})
Vue.filter('Time', (value) => {
  let m = parseInt((parseInt(value, 10) / 60), 10)
  let f = value % 60
  let mStr = m === 0 ? '00' : (m >= 10 ? m : '0' + m)
  let fStr = f === 0 ? '00' : (f >= 10 ? f : '0' + f)
  return mStr + '分钟' + fStr + '秒'
})
// window.onbeforeunload = function () {
//   return false
// }
if ('addEventListener' in document) {
  document.addEventListener('DOMContentLoaded', () => {
    FastClick.attach(document.body)
  }, false)
}
Vue.use(Router)
var router = new Router()
router.map({
  '/': {
    name: 'index',
    component: index
  },
  '/home': {
    name: 'home',
    component: watch
  },
  '/history': {
    name: 'history',
    component: (resolve) => {
      require(['./components/page/historyRoom.vue'], resolve)
    }
  },
  '/data': {
    name: 'data',
    component: (resolve) => {
      require(['./components/page/historyData.vue'], resolve)
    }
  },
  '/chart/:platform/:id': {
    name: 'chart',
    component: (resolve) => {
      require(['./components/page/chart.vue'], resolve)
    }
  },
  '/help': {
    name: 'help',
    component: (resolve) => {
      require(['./components/page/help.vue'], resolve)
    }
  }
})
router.start(App, 'app')
